package top.iflyoung.cim.biz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.iflyoung.cim.biz.entity.User;
import top.iflyoung.cim.biz.mapper.UserMapper;
import top.iflyoung.cim.biz.service.UserService;
import top.iflyoung.cim.common.util.VerifyUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author liguiyang
 * @description 用户Service的实现类
 * @sine 1.8
 * @date 2021/9/222:40
 **/
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public List<User> findUsersByType(Integer type) {
        List<User> userList = new ArrayList<>();
        if (!VerifyUtil.isEmpty(type)) {
            userList.addAll(baseMapper.queryUserList(type));
        }
        return userList;
    }

    @Override
    public User addUser(User user) {
        if (VerifyUtil.isEmpty(user)) {
            throw new NullPointerException("注册用户为空");
        }
        user.setRegisterDate(new Date());
        if (baseMapper.saveAndGet(user) > 0) {
            return user;
        }
        throw new NullPointerException("注册用户为空");
    }

    @Override
    public List<User> findOnlineUsers() {
        return baseMapper.queryAllOnlineUsers();
    }
}
